"use strict";

const BaseModel = require("../basics/mysql/mapper");

class HomeModel extends BaseModel {
  constructor(cloud) {
    super(cloud, "nk_masters");
  }

  /**
   * 获取实例
   * @param {*} cloud 
   */
  static getInstant(cloud) {
    return new HomeModel(cloud);
  }

  /**
 * 查询商户
 * @param {String} openId 
 */
  async selectOneByOpenId(openId) {
    const ex = this.createExample();
    ex.criteria.andEqual("openId", openId);
    return await this.selectOneByExample(ex);
  }

  /**
 * 查询商户
 * @param {String} appId 
 */
  async selectOneByAppId(appId) {
    const ex = this.createExample();
    ex.criteria.andEqual("appId", appId);
    ex.setOrder("id", "desc");
    return await this.selectOneByExample(ex);
  }

  /**
 * 查询商户
 * @param {String} sellerId 
 */
  async selectOneBySellerId(sellerId) {
    const ex = this.createExample();
    ex.criteria.andEqual("sellerId", sellerId);
    ex.setOrder("id", "desc");
    return await this.selectOneByExample(ex);
  }

  /**
 * 查询商户
 */
  async selectOneByDef() {
    const ex = this.createExample();
    ex.criteria.andEqual("isdef", 1);
    return await this.selectOneByExample(ex);
  }

}

module.exports = HomeModel;